home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / listings / v_09_04 / 9n04014a < prev    next >
Text File  |  1991-03-19  |  999b  |  43 lines

  1. /* _Getloc function */
  2. #include <stdio.h>
  3. #include <string.h>
  4.  
  5. /* get locale pointer, given category and name */
  6. struct lconv *_Getloc(const char *nmcat, const char *lname)
  7.     {
  8.     const char *ns, *s;
  9.     size_t nl;
  10.     struct lconv *p;
  11.  
  12.      {    /* find category component of name */
  13.     size_t n;
  14.  
  15.     for (ns = NULL, s = lname; ; s += n + 1)
  16.         {    /* look for exact match or LC_ALL */
  17.         if (s[n = strcspn(s, ":;")] == '\0' || s[n] == ';')
  18.             {    /* memorize first LC_ALL */
  19.             if (ns == NULL)
  20.                 ns = s, nl = n;
  21.             if (s[n] == '\0')
  22.                 break;
  23.             }
  24.         else if (memcmp(nmcat, s, ++n) == 0)
  25.             {    /* found exact category match */
  26.             ns = s + n, nl = strcspn(ns, ";");
  27.             break;
  28.             }
  29.         else if (s[n += strcspn(s + n, ";")] == '\0')
  30.             break;
  31.         }
  32.     if (ns == NULL)
  33.         return (NULL);    /* invalid name */
  34.      }
  35.     for (p = &_Clocale; p; p = p->_Next)
  36.         if (memcmp(p->_Name, ns, nl) == 0
  37.             && p->_Name[nl] == '\0')
  38.             return (p);
  39. /* try here to read in locale from file */
  40.     return (NULL);
  41.     }
  42.  
  43.